/*
1) Import the SSR-Einav mapping
2) Merge to SSR-ATC3 data (link molecule to SSR Product and then to ATC-3) => from jf_create_data_for_gpt45
3) Try to compute average elasticity in an ATC-3 => see how many we cover
*/

import excel using "${inputdir}\einav_merge.xlsx", firstrow clear

replace Molecule = subinstr(Molecule, "[", "", .)
replace Molecule = subinstr(Molecule, "]", "", .)
replace Molecule = subinstr(Molecule, "'", "", .)

split Molecule, p(", ")
keep elasticity Molecule*
drop Molecule

gen id = _n
reshape long Molecule, i(id) j(seq)
drop if Molecule == ""
collapse (mean) elasticity, by(Molecule)

merge 1:m Molecule using "${outdir}\main_SSR_2Q20.dta", keep(match) nogen
collapse (mean) elasticity, by(Product)

merge 1:m Product using "${inputdir}\ssr_product_atc4_codes.dta", ///
	keep(match) nogen

keep Product atc3 elasticity // two cases where a product has two ATC-4's in the same ATC-3
duplicates drop

collapse (mean) elasticity, by(atc3)

save "${outdir}\atc3_level_copay_elasticities.dta", replace
